package rz.rmi;

import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Server {
	private static final String host = "127.0.0.1";  
    private static final int port = 8800;
    
	public Server() {
        
		System.setProperty("java.security.policy", "src/rmi/server.policy");//权限控制  
          
        if(System.getSecurityManager() == null){
            System.setSecurityManager(new RMISecurityManager());  
        }//安全管理器的安装 
        try {
        	Registry registry = LocateRegistry.createRegistry(port);//注册
		} catch (RemoteException e1) {
			e1.printStackTrace();
		}
        
		try {
			
			MyRemote remote = new MyRemoteImpl();
			System.out.println(remote);
			Naming.bind("rmi://" + host + ":" + port + "/MyRemote", remote);
			
	        //registry.bind("MyRemote", remote); 
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * @param args
	 * @author ddh
	 */
	public static void main(String[] args) {
		new Server();

	}

}
